$(document).ready(function() {
	//点击注册按钮，提交昵称，邮箱，验证邮箱格式，密码，验证码
    $("#btn").click(function() {
        var uName =$("#name").val();
        var uPwd =$("#password").val();
        var uEmail =$("#email").val();
        var captch=$('#captchaInput').val();
        console.log(uName);
        if(uName== "") {
            alert("昵称不能为空");
            return false;
        }
        if (captchaInput==''){
            alert("昵称不能为空");
    }
        if(uEmail== "") {
            alert("邮箱不能为空");
            return false;
        }
        if(!uEmail.match(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/)) {
            alert("邮箱格式错误！请重新输入");
            $("#email").focus();
        }
        if(uPwd== "") {
            alert("密码不能为空");
            return false;
        }
        $.ajax({
            type:"post",
            url:"/user/register",
            data:{
                uName:uName,
                uPwd:uPwd,
                uEmail:uEmail,
                code:captch
            },
            success:function(data){
                if(data.success) {
                    alert(data.msg);
                    window.location.href = '/user/sign';
                }else{
                    alert(data.msg);
                }
            },
            error:function(data){
                alert('网络错误');
                console.log(data);
            }
        });
	});

//发送验证码
    $('#captchaBtn').click(function() {
        var time = 60;
        settime($(this));

        function settime(obj) {
            if(time == 0) {
                $(obj).attr('disabled', false);
                $(obj).html("获取验证码");
                time = 60;
                return;
            } else {
                $(obj).attr('disabled', true);
                $(obj).html(time + "秒后重新发送");
                time--;
            }
            setTimeout(function() {
                settime(obj)
            }, 1000)
        }
        var  targetEmail=$("#email").val();
        $.ajax({
            type:"post",
            url:"/user/sendEmail",
            data:{
                targetEmail:targetEmail
            },
            success:function(data){
                console.log(data.data);
                if(data.success){

                }
            },
            error:function(){

            }
        });
    });

    $(".sign-input1").onblur(function () {
        var email = $("#email").val();
        alert(email);
        $.ajax({
            type: "post",
            url: "/user/inquireEmail",
            data: {
                email:email
            },
            success: function (data) {
                alert(data.msg)
            },
            error: function () {

            }
        });
    });
	
	
	
	
	
	
	
});